package com.anyou.mall.fin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.anyou.common.annotation.ShopScope;
import com.anyou.mall.fin.domain.StoreWithdrawalAduit;
import com.anyou.mall.fin.param.RevenueParam;
import com.anyou.mall.fin.param.TixRecordParam;
import com.anyou.mall.fin.vo.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.fin.domain.StoreReconciliation;
import com.anyou.mall.fin.service.IStoreReconciliationService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 商家对账Controller
 *
 * @author gaochaohao
 * @date 2022-04-25
 */
@Api(tags = "商家对账")
@RestController
@RequestMapping("/fin/storeReconciliation")
public class StoreReconciliationController extends BaseController
{
    @Autowired
    private IStoreReconciliationService storeReconciliationService;

    /**
     * 查询商家对账列表
     */
    @ApiOperation("查询商家对账列表")
    @PreAuthorize("@ss.hasPermi('fin:storeReconciliation:list')")
    @GetMapping("/list")
    @ShopScope(baseTableAlias = "c1")
    public TableDataInfo<List<StoreReconciliationVo>> list(StoreReconciliation storeReconciliation)
    {
        startPage();
        List<StoreReconciliationVo> list = storeReconciliationService.selectStoreReconciliationList(storeReconciliation);
        return getDataTable(list);
    }

    /**
     * 导出商家对账列表
     */
    @ApiOperation("导出商家对账列表")
    @PreAuthorize("@ss.hasPermi('fin:storeReconciliation:export')")
    @Log(title = "商家对账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ShopScope(baseTableAlias = "c1")
    public void export(HttpServletResponse response, StoreReconciliation storeReconciliation)
    {
        List<StoreReconciliationVo> list = storeReconciliationService.selectStoreReconciliationList(storeReconciliation);
        ExcelUtil<StoreReconciliationVo> util = new ExcelUtil<StoreReconciliationVo>(StoreReconciliationVo.class);
        util.exportExcel(response, list, "商家对账数据");
    }

    /**
     * 获取商家对账详细信息
     */
    @ApiOperation("获取商家对账详情-累计收入/剩余可提现")
    @PreAuthorize("@ss.hasPermi('fin:storeReconciliation:query')")
    @PostMapping(value = "/getInfo")
    public ApiResult<StoreReconciliationDetails1> getInfo(@RequestParam("carPartsShopId") Long carPartsShopId)
    {
        return ApiResult.success(storeReconciliationService.selectStoreReconciliationByCarPartsShopId1(carPartsShopId));
    }

    /**
     * 获取我的收入-收入明细
     */
    @ApiOperation("获取我的收入-收入明细")
    @PreAuthorize("@ss.hasPermi('fin:storeReconciliation:myRevenue')")
    @PostMapping(value = "/myRevenue")
    public TableDataInfo<List<OrderAmountVo>> myRevenue(@Valid RevenueParam param)
    {
        startPage();
        List<OrderAmountVo> list=storeReconciliationService.selectStoreReconciliationByCarPartsShopId2(param);
        return getDataTable(list);
    }


    /**
     * 新增商家对账
     */
    @ApiOperation("新增商家对账")
    @PreAuthorize("@ss.hasPermi('fin:storeReconciliation:add')")
    @Log(title = "商家对账", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody StoreReconciliation storeReconciliation)
    {
        return ApiResult.success(storeReconciliationService.insertStoreReconciliation(storeReconciliation));
    }

    /**
     * 修改商家对账
     */
    @ApiOperation("修改商家对账")
    @PreAuthorize("@ss.hasPermi('fin:storeReconciliation:edit')")
    @Log(title = "商家对账", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody StoreReconciliation storeReconciliation)
    {
        return ApiResult.success(storeReconciliationService.updateStoreReconciliation(storeReconciliation));
    }

    /**
     * 删除商家对账
     */
    @ApiOperation("删除商家对账")
    @PreAuthorize("@ss.hasPermi('fin:storeReconciliation:remove')")
    @Log(title = "商家对账", businessType = BusinessType.DELETE)
    @DeleteMapping("/{storeReconciliationIds}")
    public ApiResult remove(@PathVariable Long[] storeReconciliationIds)
    {
        return ApiResult.success(storeReconciliationService.deleteStoreReconciliationByStoreReconciliationIds(storeReconciliationIds));
    }

    /**
     * 商家提现记录
     */
    @ApiOperation("商家提现记录")
    @PreAuthorize("@ss.hasPermi('fin:storeReconciliation:record')")
    @GetMapping("/record/getByCarPartsShopId")
    public TableDataInfo<List<StoreWithdrawalRecordVo>> record(@Valid TixRecordParam  param ) {
        startPage();
        List<StoreWithdrawalRecordVo> recordList = storeReconciliationService.getRecord2(param);
        return getDataTable(recordList);
    }
}
